package com.xuehu.cloud.controller;

import com.xuehu.cloud.entities.CommonResult;
import com.xuehu.cloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author guoweia@cslc.com.cn
 * @createTime 2020/11/18 14:31
 * @description
 */
@Slf4j
@RestController
public class OrderController {
    //private  static final String baseUri = "http://localhost:8001";
    private  static final String baseUri = "http://xuehu-payment-service";//注意大小写

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/order/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        String url = baseUri + "/pay/get/" + id;
        return restTemplate.getForObject(url, CommonResult.class);
    }

    @GetMapping("/order/create")
    public CommonResult<Payment> create(Payment payment) {
        String url = baseUri + "/pay/create";
        return restTemplate.postForObject(url, payment, CommonResult.class);
    }
}
